'''
自动存取款机
1、用户数据
2、登录账号
3、查询余额
4、存钱
5、取钱
6、登出账号
7、help
8、界面与交互
'''

# 1.用户数据
#所有信息
user_list = [
    {'name':'zhangsan','account':'111111','password':'123456','balance':10000},
    {'name':'lisi','account':'222222','password':'123456','balance':20000},
    {'name':'wangwu','account':'333333','password':'123456','balance':30000},
    {'name':'zhaoliu','account':'444444','password':'123456','balance':40000}]
#当前信息
user_now = []

# 2.登录账号
def user_login():
    global user_now
    a = input('请输入用户名：')
    p = input('请驶入密码：')
    for i, user_dict in enumerate(user_list):
        if user_dict['account'] == a and user_dict['password'] == p:
            user_now.append(i)
            user_now.append(user_dict['account'])
    if user_now != []:
        print('欢迎您：{}'.format(user_list[user_now[0]]['name']))
        print('----------登陆成功----------')
    else:
        print('-----账号或密码错误，请重新输入-----')
        user_login()

# 3.查询余额
def user_balance():
    print('您的账户余额为{}元'.format(user_list[user_now[0]]['balance']))

# 4.存钱
def user_savemoney():
    money = int(input('请输入存储金额：'))
    user_list[user_now[0]]['balance'] += money
    print('您已成功存款{}元'.format(money))
    print('您目前的余额为{}元'.format(user_list[user_now[0]]['balance']))

# 5.取钱
def user_withdrawmoney():
    money = int(input('请输入取出金额：'))
    if user_list[user_now[0]]['balance'] >= money:
        user_list[user_now[0]]['balance'] -= money
        print('您已成功取款{}元!'.format(money))
        print('您目前的余额为{}元'.format(user_list[user_now[0]]['balance']))
    else:
        print('您的余额不足，请重新输入')
        user_withdrawmoney()

# 6.登出账号
def user_Logout():
    print('='*21,'再见！','='*22)

# 7.help
def user_help():
    print('请联系：95555')

# 8.界面与交互
while True:
    # 输出初始界面
    print('='*19,'自动存取款机','='*19)
    print('='*50)
    print('{:1} {:15} {:15} {:15}'.format(' ','1.登录账号','2.查询余额','3.个人存钱'))
    print('{:1} {:15} {:15} {:15}'.format(' ','4.个人取钱','5.寻求帮助','6.登出账号'))
    print('='*50)
    key = input('请输入对应的选择：')
    # 根据输入操作值，执行对应操作
    if key == '1':
        if user_now != []:
            print('您已经登陆')
        else:
            user_login()
    elif key == '2':
        if user_now == []:
            print('您尚未登陆，请先登录')
        else:
            user_balance()
            input('按回车继续')
    elif key == '3':
        if user_now == []:
            print('您尚未登陆，请先登录')
        else:
            user_savemoney()
            input('按回车继续')
    elif key == '4':
        if user_now == []:
            print('您尚未登陆，请先登录')
        else:
            user_withdrawmoney()
            input('按回车继续')
    elif key == '5':
        user_help()
    elif key == '6':
        user_Logout()
        break
    else:
        print('输入错误，请重新输入')



'''
#测试2
user_login()
'''
'''
#测试3
user_login()
user_balance()
'''
'''
#测试4
user_login()
user_balance()
user_savemoney()
'''
'''
#测试5
user_login()
user_balance()
user_withdrawmoney()]
'''

